
#define _GNU_SOURCE
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

void *first_thread_func(void *arg) {
    printf("first 线程（%d）开始执行\n", gettid());
    sleep(2);
    printf("first 线程（%d）执行完毕\n", gettid());
    return NULL;
}
void *second_thread_func(void *arg) {
    printf("second 线程（%d）开始执行\n", gettid());
    sleep(3);
    printf("second 线程（%d）执行完毕\n", gettid());
    return NULL;
}
int main(int argc, char const *argv[])
{
    printf("main 线程（%d）开始执行\n", gettid());
    //创建两个分线程
    pthread_t tid1, tid2;
     pthread_create(&tid1, NULL,first_thread_func, NULL);
    pthread_create(&tid2, NULL,second_thread_func, NULL);
   
    
    // printf("main (%d)继续执行 pthread1=%lu, thread2=%lu\n", gettid(), tid1, tid2);
    //等待两个分线程结束
     pthread_join(tid2, NULL);
    pthread_join(tid1, NULL);
    
    
   
    printf("main 线程（%d）执行完毕\n", gettid());



    return 0;
}
